package com.sardine.base.utils;

import com.alibaba.fastjson.JSON;

import java.util.List;

/**
 * 北京京东世纪贸易有限公司<br>
 * Created with IntelliJ IDEA.
 * Date:2015/10/18
 * Time:11:18
 *
 * @author daifeng<br>
 *         daifeng@jd.com
 * @since JDK 1.6 <br>
 * Copyright (c) 2015 JD System Incorporated All Rights Reserved.
 */
public class JsonUtils {

    public static <T> T fromJson(String jsonString, Class<T> clazz) {
        return JSON.parseObject(jsonString, clazz);
    }

    public static <T> List<T> fromJsonArray(String jsonArray, Class<T> clazz) {
        return JSON.parseArray(jsonArray, clazz);
    }

    public static String toJson(Object object) {
        return toJsonWithDateFormat(object, "yyyy-MM-dd HH:mm:ss");
    }

    public static String toJsonWithDateFormat(Object object,String pattern) {
        return JSON.toJSONStringWithDateFormat(object, pattern);
    }
}
